#!usr/local/bin/python2.7
# -*- coding: utf-8 -*-

##@package DataParser
# @author Bretton Murphy and Jerimiah Davis
# @date Spring 2011
#
#This module's purpose is to recieve a string packet containing
#TelosB Wireless Sensor mote data and decode the string into readable
#information.
#

import struct

##Decodes a packet into readable data.
#
# Takes a packet String containing mote data to be decoded.  This data will be put into a 
# dictionary and will contain the port numbers of the sensor giving off the data.
#
# @param packet The packet to decode 
# @return A dictionary of mote data
def decodePacket(packet):

    #Is packet a string
    if isinstance(packet, str):
    
        #Give number of bytes in this format
        format = "!IBBIHBHHHHHHHH" 
 
        #Unpack packet into tuple
        data = struct.unpack(format, packet)
	print data        
        #Give the keys, in this case port numbers, for the dictionary
        fields = ('head', '', 'id', '', '', 'seq', 0, 1, 2, 3, 4, 5, 6, 7)
        return dict(zip(fields, data)) 
        
    else:
        print "Wrong packet type.  Packet is not of type String."
